﻿using System;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace YJKArch.ImportStructureProject
{
	[Transaction(TransactionMode.Manual)]
	[Regeneration(RegenerationOption.Manual)]
	public class StructureImport : IExternalCommand
	{
		public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elems)
		{
			Result result3;
			try
			{
				if (cmdData == null)
				{
					throw new System.ArgumentNullException("commandData");
				}
				DlgSynergyType dlgSynergyType = new DlgSynergyType(1);
				dlgSynergyType.ReadDlgData("StructureImport");
				if (dlgSynergyType.ShowDialog() == DialogResult.OK)
				{
					dlgSynergyType.SaveDlgData("StructureImport");
					if (dlgSynergyType.SynergyType == 0)
					{
						Result result = new Importer(cmdData).ImportFromXMLFile(dlgSynergyType.FileName, ref msg);
						if (result != null)
						{
							return result;
						}
					}
					else if (dlgSynergyType.SynergyType == 1)
					{
						Result result2 = new Importer(cmdData).ImportFromDatabase(ref msg);
						if (result2 != null)
						{
							return result2;
						}
					}
				}
				result3 = Autodesk.Revit.UI.Result.Succeeded;
			}
			catch (Exception ex)
			{
				msg = ex.Message;
				result3 = Autodesk.Revit.UI.Result.Failed;
			}
			return result3;
		}
	}
}
